package cn.zxhysy.booksmall.controller;

import cn.zxhysy.booksmall.entity.Car;
import cn.zxhysy.booksmall.entity.ProLine;
import cn.zxhysy.booksmall.entity.ProductOrder;
import cn.zxhysy.booksmall.entity.User;
import cn.zxhysy.booksmall.utils.ApiJSONResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "信息获取接口", tags = "信息获取")
@RestController
@RequestMapping(value = {"/car", "/api/car"})
public class CarController {
    private final BasicController basicController;

    @Autowired
    public CarController(BasicController basicController) {
        this.basicController = basicController;
    }

    @GetMapping
    public ApiJSONResult findAll(HttpServletRequest request) {
        String concreteName = String.valueOf(request.getSession().getAttribute(BasicController.CONCRETE_NAME));
        List<Car> waitCarList = this.basicController.carService.getWaitCarList(concreteName);
        List<ProLine> proLineList = this.basicController.proLineService.findAll(concreteName);
        List<ProductOrder> productOrderList = this.basicController.productOrderService.findAll(concreteName);

        Map<String, Object> map = new HashMap<>();
        map.put("waitCarList", waitCarList);
        map.put("proLineList", proLineList);
        map.put("productOrderList", productOrderList);
        return ApiJSONResult.ok(map);
    }
}
